﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyMvc.BLL;
using MyMvc.Common;
using MyMvc.IBLL;
using MyMvc.Model;
using MyMvc.Model.Models;

namespace BlueHome.Admin.Controllers
{
    public class ProjectController : Controller
    {
        //
        // GET: /Project/

        public ActionResult Index()
        {
            return View();
        }

        IArticleService _protectService = new ArticleService();
        /// <summary>
        /// 实现添加信息
        /// </summary>
        /// <param name="art"></param>
        /// <returns></returns>
        public ActionResult AddFile(Article art)
        {
            art.Content1 = Server.UrlDecode(art.Content1);
            //实现对StudentsInfo表的添加信息
            _protectService.AddEntities(art);
            return Content("OK");
        }

        //public ActionResult AddFile(string artStr)
        //{
        //    Article art = Newtonsoft.Json.JsonConvert.DeserializeObject(artStr) as Article;
        //    //实现对StudentsInfo表的添加信息
        //    _protectService.AddEntities(art);
        //    return Content("OK");
        //}

        IArticleService _literatureService = new ArticleService();
        //得到所有文档信息
        public ActionResult GetAllLiterature()
        {


            //分页的数据
            //
            int pageIndex = Request["page"] == null ? 1 : int.Parse(Request["page"]);
            int pageSize = Request["rows"] == null ? 10 : int.Parse(Request["rows"]);

            //封装一个业务逻辑层，来处理分页过滤的事件
            GetModelQuery literatureInfoQuery = new GetModelQuery();
            literatureInfoQuery.pageIndex = pageIndex;
            literatureInfoQuery.pageSize = pageSize;
            literatureInfoQuery.total = 0;

            //放置依赖刷新
            var data = from u in _literatureService.LoadSearchData(literatureInfoQuery)
                       select new { u.ID, u.Title, u.Author, u.Content1, u.CreateDateTime };

            //var data = _userInfoService.LoadPagerEntities(pageSize, pageIndex, out total, u => true, true, u => u.ID);

            var result = new { total = literatureInfoQuery.total, rows = data };

            return Json(result, JsonRequestBehavior.AllowGet);
        }
    }
}
